//
// SystemMessage
//
function SystemMessage(cfg) {
		this.view = new SystemMessageView(this);
		this.cookie_name = this.view.getCookieName();
		//window.console.log(this.cookie_name);

		if (typeof cfg == 'object') for (var i in cfg) this[i] = cfg[i]; 
}
// show the message
SystemMessage.prototype.getMessage = function () { return jQuery.cookie(this.cookie_name) }
// dismiss the message
SystemMessage.prototype.dismiss = function () {
		if (jQuery.cookie(this.cookie_name)) {
			//window.console.log('dismissed');
			jQuery.cookie(this.cookie_name, null, {'path': '/'});
		}
		return this;
}
SystemMessage.prototype.show = function () {
		var msg = this.getMessage();
		//window.console.log(msg, this.cookie_name);
		if (msg) { this.view.setMessage(msg).show(); }
		return this;
}

//
// SystemMessageView
//
function SystemMessageView(model) {
		this.model = model;
		this.bind();
}
SystemMessageView.prototype.bind = function () {
		var self = this;
		var rh_alert = jQuery('#rh_alert');
		rh_alert.removeClass('dn').hide();
		rh_alert.find('.close-').bind('click', function(event) { self.hide(); });
		setTimeout(function () { self.hide() }, 10000);
		return this;
}
SystemMessageView.prototype.setMessage = function (msg) { 
		jQuery('#rh_message').get(0).innerHTML = msg; 
		return this; 
}
SystemMessageView.prototype.getCookieName = function () { 
		return jQuery('#rh_message').get(0).innerHTML;
}
SystemMessageView.prototype.show = function () { 
		jQuery('.html-layout-2-1-1').addClass('html-alert-title');
		jQuery('#rh_alert').show(); 
		return this; 
}
SystemMessageView.prototype.hide = function () { 
		jQuery('.html-layout-2-1-1').removeClass('html-alert-title');
		jQuery('#rh_alert').hide();
		return this; 
}

jQuery().ready(function () {
    (new SystemMessage()).show().dismiss();
});

